package com.gxa.controller.investment;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.Result;
import com.gxa.dto.investmentDto.CompanyQuitDto;
import com.gxa.dto.investmentDto.CompanyQuitResult;
import com.gxa.entity.investment.Company;
import com.gxa.entity.investment.CompanyQuit;
import com.gxa.service.investment.CompanyQuitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 退园管理 前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-16 11:39:46
 */
@Api(tags = "企业管理/退园管理")
@RestController
@RequestMapping("/company/quit")
public class CompanyQuitController {

    @Autowired
    private CompanyQuitService companyQuitService;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("添加退园企业")
    @PostMapping("/add")
    public Result add(@RequestBody CompanyQuit companyQuit){
        try {
            int result = companyQuitService.add(companyQuit);
            if (result == 1){
                return Result.success("add success");
            }else {
                return Result.failed("add failed");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑退园企业")
    @PutMapping("/update")
    public Result update(@RequestBody CompanyQuit companyQuit){
        System.out.println(companyQuit);
        try {
            int result = companyQuitService.update(companyQuit);
            if (result == 1){
                return Result.success("update success");
            }else {
                return Result.failed("update failed");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("查询退园企业")
    @PostMapping ("/query")
    public Result query(Integer pageNum, Integer pageSize,@RequestBody CompanyQuitDto companyQuitDto){
        try {
            PageInfo result = companyQuitService.queryByCompanyQuitDto(companyQuitDto, pageNum, pageSize);

            return Result.success(result);
        }catch (Exception e){
            e.printStackTrace();
            return Result.failed("query failed");
        }
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("查询退园企业(查不上用这个")
    @GetMapping("/list")
    public Result listAll(){
      List<CompanyQuitResult> list= companyQuitService.selectAll();
        return Result.success(list);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("查询退园企业详情")
    @GetMapping("/query/{id}")
    public Result queryById(@PathVariable("id")Integer id){
        try {
            CompanyQuitResult result = companyQuitService.queryById(id);
            if (result != null){
                return Result.success(result);
            }else {
                return Result.failed("query failed");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;

    }

}
